package com.sanyang.pda.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sanyang.pda.bean.StockStatisticsBean;
import com.sanyang.pda.utils.StringConfig;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.adapter.BaseAdapter;
import com.wangshen.projectbase.R;

import java.util.List;

public class StockStatisticsAdapter extends BaseAdapter<StockStatisticsBean> {
    private String taskNo;
    public StockStatisticsAdapter(int layoutResId, @Nullable List<StockStatisticsBean> data,String taskNo ) {
        super(layoutResId, data);
        this.taskNo=taskNo;
    }

    @Override
    protected void convert(BaseViewHolder helper, StockStatisticsBean item) {
        super.convert(helper, item);
        helper.setText(R.id.tv_name,item.getWareareaId());
        helper.setText(R.id.tv_have_inventory,item.getIsCountedCount()+"");
        helper.setText(R.id.tv_for_inventory,item.getNoCountedCount()+"");
        helper.setText(R.id.tv_inventory_profit,item.getYinCount()+"");
        helper.setText(R.id.tv_inventory_losses,item.getKuiCount()+"");
        helper.setText(R.id.tv_rateStr,getContext().getString(R.string.plan)+" "+item.getRateStr());
        CheckBox checkBox=helper.getView(R.id.cb_rateStr);
        RecyclerView recyclerView=helper.getView(R.id.rv_list);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    recyclerView.setVisibility(View.VISIBLE);
                }else {
                    recyclerView.setVisibility(View.GONE);
                }
            }
        });

        StockStatisticsListAdapter adapter=new StockStatisticsListAdapter(R.layout.item_stock_statistics_list,item.getStatisticsByStoragebinList());
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                StockStatisticsBean.StatisticsByStoragebinListBean stockStatisticsBean= (StockStatisticsBean.StatisticsByStoragebinListBean) adapter.getData().get(position);
                Bundle bundle=new Bundle();
                bundle.putString(StringConfig.STORAGEBINID,stockStatisticsBean.getStoragebinId());
                bundle.putString(StringConfig.TASKNO,taskNo);
                ARouter.getInstance().build(AppActivityKey.STOCKSTATISTICSDETAILACTIVITY).with(bundle).navigation(getContext());
            }
        });
    }
}
